import request from "@/utils/request";

// 获取管理员列表
export function getUserList () {
    return request ({
        url: 'backend/backendMember/read',
        method: 'GET'
    })
}

// 添加/编辑管理员,获取角色
export function editorAdmin () {
    return request ({
        url: 'backend/backendMember/create',
        method: 'GET'
    })
}

// 添加管理员
export function addAdmin (data) {
    return request ({
        url: 'backend/backendMember/save',
        method: 'POST',
        data: {
            username: data.username,
            account: data.account,
            password: data.password,
            role_id: data.role_id,
            avatar: data.avatar,
            introduction: data.introduction,
            status: data.status
        }
    })
}

// 编辑管理员获取的信息
export function editorAdminInfo (id) {
    return request ({
        url: 'backend/backendMember/edit?id=' + id,
        method: 'GET',
        data: {
            id: id
        }
    })
}

// 编辑管理员
export function editorAdminChange (data) {
    return request ({
        url: 'backend/backendMember/update',
        method: 'POST',
        data: {
            id: data.id,
            username: data.username,
            account: data.account,
            password: data.password,
            role_id: data.role_id,
            avatar: data.avatar,
            introduction: data.introduction,
            status: data.status
        }
    })
}

// 删除管理员
export function deleteAdmin (id) {
    return request ({
        url: `backend/backendMember/delete?id=${id}`,
        method: 'DELETE'
    })
}

/**
 * 获取后台角色
 * 角色包括,普通管理员,超级管理员等字段信息
 */

// 角色管理


// 获取角色列表
export function roleList () {
    return request ({
        url: 'backend/role/index',
        method: 'GET'
    })
}

// 添加角色
export function addRole (data) {
    return request ({
        url: 'backend/role/save',
        method: 'POST',
        data: {
            role_name: data.role_name,
            status: data.status
        }
    })
}

// 编辑角色获取信息
export function editorRoleInfo (id) {
    return request ({
        url: `backend/role/edit?id=${id}`,
        method: 'POST',
        data: {
            id: id
        }
    })
}

// 编辑角色
export function editorRole (data) {
    return request ({
        url: 'backend/role/update',
        method: 'POST',
        data: {
            id: data.id,
            role_name: data.role_name,
            status: data.status
        }
    })
}

// 删除角色
export function deleteRole (id) {
    return request ({
        url: `backend/role/delete?id=${id}`,
        method: 'DELETE'
    })
}

/**
 * 获取节点
 * 路由节点管理
 */
// 获取路由节点
export function getRouterList () {
    return request ({
        url: 'backend/permission/index',
        method: 'GET'
    })
}

// 编辑获取信息  Api文档写的屁玩意,***************的,*****.
// export function editorRouterInfo(id){
//     return request({
//         url: `backend/permission/create`
//     })
// }


// 添加节点
export function addRouter (data) {
    return request ({
        url: 'backend/permission/save',
        method: 'POST',
        data: {
            title: data.title,
            action: data.action,
            component: data.component,
            icon: data.icon,
            pid: data.pid,
            status: data.status
        }
    })
}

// 编辑节点获取信息
export function editorRouterInfo (id) {
    return request ({
        url: `backend/permission/edit?id=${id}`,
        method: 'GET',
        data: {
            id: id
        }
    })
}

// 编辑节点
export function editorRouter (data) {
    return request ({
        url: 'backend/permission/update',
        methodL: 'POST',
        data: {
            id: data.id,
            title: data.title,
            action: data.action,
            component: data.component,
            icon: data.icon,
            pid: data.pid,
            status: data.status
        }
    })
}

// 删除节点
export function deleteRouter (id) {
    return request ({
        url: `backend/permission/delete?id=${id}`,
        method: 'DELETE',
        data: {
            id: id
        }
    })
}

/**
 * 获取角色权限
 * 权限列表,增加角色权限等操作
 */
export function permissionList () {
    return request ({
        url: 'backend/rolePermission/index',
        method: 'GET'
    })
}

// 添加/编辑获取信息
export function editorPermissionInfo () {
    return request ({
        url: 'backend/rolePermission/create',
        method: 'GET'
    })
}

// 添加角色权限
export function addRolePermission (data) {
    return request ({
        url: 'backend/rolePermission/save',
        method: 'POST',
        data: {
            role_id: data.role_id,
            permission_id: data.permission_id,
            status: data.status
        }
    })
}

// 编辑角色权限获取信息
export function editorUserRoleInfo (id) {
    return request ({
        url: 'backend/rolePermission/edit',
        method: 'GET',
        data: {
            id: id
        }
    })
}

/**
 *
 * @param data 接口递值
 * @returns {AxiosPromise}
 */
export function editorUserInfoChange (data) {
    return request ({
        url: 'backend/rolePermission/update',
        method: 'POST',
        data: {
            /**
             * id: 角色权限id
             * role_id   角色id
             * permission_id  节点id
             * status: 状态
             */
            id: data.id,
            role_id: data.role_id,
            permission_id: data.permission_id,
            status: data.status
        }
    })
}

/**
 * 删除角色权限
 * @param id  角色权限id
 * @returns {AxiosPromise}
 */
export function deleteUserPermission (id) {
    return request ({
        url: `backend/rolePermission/delete?id=${id}`,
        method: 'DELETE',
        data: {
            id: id
        }
    })
}



